package com.beyondthewalls.factories;

import com.almasb.fxgl.dsl.FXGL;
import com.almasb.fxgl.entity.Entity;
import com.almasb.fxgl.entity.EntityFactory;
import com.almasb.fxgl.entity.SpawnData;
import com.almasb.fxgl.entity.Spawns;
import com.almasb.fxgl.physics.BoundingShape;
import com.beyondthewalls.components.*;
import com.beyondthewalls.utils.Type;

public class JumpFactory implements EntityFactory {
    @Spawns("bat")
    public Entity newBat(SpawnData data) {
        double width = Double.parseDouble(data.get("width").toString());
        double height = Double.parseDouble(data.get("height").toString());

        return FXGL.entityBuilder(data)
                .type(Type.hit)
                .bbox(BoundingShape.box(width, height))
                .with(new Bat())
                .build();
    }

    @Spawns("plant2")
    public Entity newPlant2(SpawnData data) {
        double width = Double.parseDouble(data.get("width").toString());
        double height = Double.parseDouble(data.get("height").toString());

        return FXGL.entityBuilder(data)
                .type(Type.plant2)
                .bbox(BoundingShape.box(width, height))
                .with(new Plant2())
                .build();
    }

    @Spawns("plant3")
    public Entity newPlant3(SpawnData data) {
        return FXGL.entityBuilder(data)
                .type(Type.plant2)
                .viewWithBBox("plant2.png")
                .with(new Plant2())
                .build();
    }

    @Spawns("stab")
    public Entity newStab(SpawnData data) {
        double width = Double.parseDouble(data.get("width").toString());
        double height = Double.parseDouble(data.get("height").toString());

        return FXGL.entityBuilder(data)
                .type(Type.hit)
                .bbox(BoundingShape.box(width, height))
                .collidable()
                .build();
    }

    @Spawns("water")
    public Entity newWater(SpawnData data) {
        double width = Double.parseDouble(data.get("width").toString());
        double height = Double.parseDouble(data.get("height").toString());
        int tx = Integer.parseInt((data.get("tx").toString()));
        int ty = Integer.parseInt((data.get("ty").toString()));

        return FXGL.entityBuilder(data)
                .type(Type.water)
                .bbox(BoundingShape.box(width, height))
                .with(new Water(tx, ty))
                .build();
    }

    @Spawns("air")
    public Entity newAir(SpawnData data) {
        double width = Double.parseDouble(data.get("width").toString());
        double height = Double.parseDouble(data.get("height").toString());
        int d = data.get("direction");

        return FXGL.entityBuilder(data)
                .with(new Air(width, height, d))
                .build();
    }

    @Spawns("energy")
    public Entity newEnergy(SpawnData data) {
        return FXGL.entityBuilder(data)
                .with(new Energy())
                .build();
    }
}
